package system.security.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import system.security.dao.RoleDao;
import system.security.entity.Role;
import system.security.service.RoleService;


@Service("roleService")
public class RoleServiceImpl implements RoleService {

	@Autowired
	RoleDao roleDao;
	
	@Transactional(readOnly=true)
	@Override
	public Role getById(int roleId) {
		Role role = roleDao.get(roleId);
		return role;
	}

	@Override
	public Role findByName(String rolename) {
			List<Role> list = roleDao.findByProperty("rolename", rolename);
			if(!list.isEmpty()){
				return list.get(0);
			}
			return null;		
	}

	@Override
	@Transactional(readOnly = true)
	public List<Role> getAll() {
		return roleDao.list();
	}
	
	@Override
	public void save(Role role) throws Exception {
			roleDao.saveOrUpdate(role);
	}

	@Override
	public void delete(int roleId) {
		roleDao.remove(roleId);
	}
	
	@Override
	public void delete(Role role){
		roleDao.remove(role);		
	}

	
}
